
#import "APAuthorizationManager.h"
#import <AssetsLibrary/AssetsLibrary.h>
#import <Photos/Photos.h>

@implementation APAuthorizationManager


+ (BOOL)canUseCaptureDevice{
    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied){
        return NO;
    }
    return YES;
}

+(BOOL)isCanUsePhotos{
    PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
    if (status == PHAuthorizationStatusRestricted ||
        status == PHAuthorizationStatusDenied) {
        return NO;
    }
//    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) {
//        ALAuthorizationStatus author =[ALAssetsLibrary authorizationStatus];
//        if (author == ALAuthorizationStatusRestricted || author == ALAuthorizationStatusDenied) {
//            return NO;
//        }
//    }else {
//       PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
//    if (status == PHAuthorizationStatusRestricted ||
//        status == PHAuthorizationStatusDenied) {
//        return NO;
//    }
//    }
    return YES;
}


//+ (BOOL)allowInternetService{
//
//    CTCellularData *cellularData = [[CTCellularData alloc]init];
//    CTCellularDataRestrictedState state = cellularData.restrictedState;
//    switch (state) {
//        case kCTCellularDataRestricted:
//            NSLog(@"Restricrted");
//            break;
//        case kCTCellularDataNotRestricted:
//            NSLog(@"Not Restricted");
//            break;
//        case kCTCellularDataRestrictedStateUnknown:
//            NSLog(@"Unknown");
//            break;
//        default:
//            break;
//    }
//}

+ (void)jumpToSetting{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];

}



+ (void)jumpToInternetSetting{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];

}

+ (void)showInternetServiceAlertIn:(UIViewController *)vc{
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];
    NSString *msg = [NSString stringWithFormat:@"'%@'no network",app_Name];
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"tip" message:msg preferredStyle:UIAlertControllerStyleAlert];
    [alertVC addAction:[UIAlertAction actionWithTitle:@"setting" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [APAuthorizationManager jumpToInternetSetting];
    }]];
    [alertVC addAction:[UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleCancel handler:nil]];
    [vc presentViewController:alertVC animated:YES completion:nil];
}


@end
